import React, { Component } from 'react'
import { connect } from 'react-redux';
import { BrowserRouter as Router, Redirect, Route, NavLink, Switch } from 'react-router-dom';
import './my.css'

class Login extends Component{
	constructor(props) {
	    super(props);
	}
	render(props) {
		return (
			
			<div style={{textAlign:"center"}} id='login-box'>,
				<div id='login-bijian'>笔尖</div>
				<span> 开启文字之旅</span><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
				<div style={{margin:'20px'}}><input type="text" id="nicheng" placeholder="昵称" style={{height:'40px', width:'300px', border:'2px solid #73C1F3', borderRadius:'10px'}}/></div>
				<div style={{margin:'20px'}}><input type="password" id="mima" placeholder="请输入登录密码" style={{height:'40px', width:'300px', border:'2px solid #73C1F3', borderRadius:'10px'}}/></div>,
				<button style={{height:'30px', width:'300px', backgroundColor:'#73C1F3', borderRadius:'10px'}} 
					onClick={() => {
						var nicheng = document.getElementById('nicheng').value;
						var mima = document.getElementById('mima').value;
						
						fetch('http://62.234.30.197:8088/userlist/chaid', {
							method: 'post',
							body: JSON.stringify({'name':`${nicheng}`}),
							headers: {
							    "Access-Control-Allow-Origin":"*",
							    'content-type': 'application/json'
							},
							mode: 'cors'
						})
						.then(res=>res.json())
						.then(res=> {
							if(res.length > 0) {
								alert('注册失败！');
							}
							else {
								//注册成功
								fetch('http://62.234.30.197:8088/userlist/zeng', {
									method: 'post',
									body: JSON.stringify({'name':`${nicheng}`,'pic':'http://qkpa8y0ib.hb-bkt.clouddn.com/pic13.jpg','password':`${mima}`}),
									headers: {
									    "Access-Control-Allow-Origin":"*",
									    'content-type': 'application/json'
									},
									mode: 'cors'
								})
								.then(res=>res.json())
								.then(res=> {
									//console.log(res)
								})
								this.props.history.push('/Login')
							}
						})
						
						
						
					}} >注册</button>
			</div>
		)
	}
}


//export default connect(null, { login })(Login)
export default Login;

// 	<button onClick={this.userlistzeng}>增用户</button><br />
  //    userlistzeng() {
  //   		console.log('userlistzeng');
  //   		fetch('http://62.234.30.197:8088/userlist/zeng', {
  //   			method: 'post',
  //   			body: JSON.stringify({'name':'增加的','pic':'zheshi pic','password':'zheshi password'}),
  //   			headers: {
  //   			    "Access-Control-Allow-Origin":"*",
  //   			    'content-type': 'application/json'
  //   			},
  //   			mode: 'cors'
  //   		})
  //   		.then(res=>res.json())
  //   		.then(res=> {
  //   			console.log(res)
  //   		})
  //   	}